const path = require('path');
const alias = require('./alias.js');
const globalLessVal = require('./src/styles/index');
// eslint-disable-next-line no-unused-vars
function resolve(dir) {
  return path.join(__dirname, dir);
}
const cdnJs = [
  'https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js',
  'http://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.3.0'
];
const proxy = {
  // http://v1.zcloudtechs.cn http://10.7.7.6:10080/ http://10.7.7.10:10080/
  '(/)': {
    target: 'http://49.233.85.23:8080',
    ws: true,
    changeOrigin: true
  }
};
module.exports = {
  publicPath: process.env.BASE_URL,
  productionSourceMap: false,
  devServer: {
    // disableHostCheck: true,
    open: true,
    port: 9090,
    hotOnly: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy
  },
  css: {
    loaderOptions: {
      less: {
        globalVars: globalLessVal
      }
    }
  },
  chainWebpack: (config) => {
    // 别名
    for (let aliasKey in alias) {
      config.resolve.alias.set(aliasKey, alias[aliasKey]);
      console.log(aliasKey);
    }
    config.plugins.delete('prefetch');
    config.plugins.delete('preload');
    config.plugin('html').tap((args) => {
      args[0].cdnJs = cdnJs;
      return args;
    });
    return config;
  }
};
